using System;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.SharePoint.WebPartPages;
using PS.WebParts.Rollup;
using PS.WebParts.Rollup.Query;

namespace PS.WebParts
{
    [Designer("PS.WebParts.Rollup.Designers.CrossSiteDataSourceDesigner, PS.WebParts.Rollup.Designers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f4a26fd125a021e")]
    public class SqlRollupDataSource : RollUpDataSource
    {
        protected override ATabularDataSourceView CreateViewInstance()
        {
            SqlRollupDataView view = new SqlRollupDataView(base.Context, this, string.Empty);
            return view;
        }

        [Obsolete, Bindable(false), Browsable(false), PersistenceMode(PersistenceMode.InnerProperty)]
        public string Where
        {
            set
            {
                base.Query = "<Where>" + value + "</Where>";
            }
        }

        [FriendlyName("Content Type"), Description(""), Browsable(true), DefaultValue("")]
        public string ContentType
        {
            get
            {
                return ((SqlRollupDataView)DSView).ContentType;
            }
            set
            {
                ((SqlRollupDataView)DSView).ContentType = value;
            }
        }

        new public bool? IncludeListData
        {
            get
            {
                bool v = (int)((SqlRollupDataView)DSView).IncludeMetadata != 0;
                return v ? true : (bool?)null;
            }
            set
            {
                if (value.HasValue)
                    ((SqlRollupDataView)DSView).IncludeMetadata = value.Value ? IncludeMetaDataOptions.IDs | IncludeMetaDataOptions.Item | IncludeMetaDataOptions.List | IncludeMetaDataOptions.Web : IncludeMetaDataOptions.IDs;
            }
        }
    }
}